package br.com.carser.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.carser.model.Profile;

/**
 * Convert profile object.
 * 
 * @author Eduardo T. Serete
 */
@FacesConverter(forClass=Profile.class, value="profileConverter")
public class ProfileConverter implements Converter {

//	private ProfileBusiness profileBusinessBean;
	
	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		if (arg2 != null && !arg2.isEmpty()) {
			return new Profile();
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		if (arg2 != null) {
			if (arg2 instanceof Profile) {
				return ((Profile) arg2).getName();
			}
		}
		return null;
	}

}